#include "Ogre.h"
#include "GameEngine.h"
#include "Actor.h"
#include "Avatar.h"

CAvatar::CAvatar()
{
	mHair	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Hair",	"m_hair.mesh");
	mHead	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Head",	"m_head.mesh");
	mTorso	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Torso",	"m_torso.mesh");
	mArm	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Arm",	"m_arm.mesh");
	mLeg	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Leg",	"m_leg.mesh");
	mBoot	= CGameEngine::getSingletonPtr()->getSceneManager()->createEntity("Boot",	"m_boot.mesh");

	mBoot->shareSkeletonInstanceWith(mHair);
	mBoot->shareSkeletonInstanceWith(mHead);
	mBoot->shareSkeletonInstanceWith(mTorso);
	mBoot->shareSkeletonInstanceWith(mArm);
	mBoot->shareSkeletonInstanceWith(mLeg);

	getSceneNode()->attachObject(mHair);
	getSceneNode()->attachObject(mHead);
	getSceneNode()->attachObject(mTorso);
	getSceneNode()->attachObject(mArm);
	getSceneNode()->attachObject(mLeg);
	getSceneNode()->attachObject(mBoot);

	//Set up the skeleton to be manually controlled
	mAnimationMelee = mBoot->getAnimationState("melee");
	mAnimationMelee->setEnabled(true);
	mAnimationMelee->setLoop(true);

}

CAvatar::~CAvatar()
{
}

void CAvatar::tickAnimation(Ogre::Real delta)
{
	mAnimationMelee->addTime(delta);

	//mHair->getAllAnimationStates()->_notifyDirty();
	//mHair->_updateAnimation();
	//mHead->getAllAnimationStates()->_notifyDirty();
	//mHead->_updateAnimation();
	//mArm->getAllAnimationStates()->_notifyDirty();
	//mArm->_updateAnimation();
	//mBoot->getAllAnimationStates()->_notifyDirty();
	//mBoot->_updateAnimation();
}